package com.simoniu.first.dao.impl;

import com.simoniu.first.dao.UsersDao;
import com.simoniu.first.utils.DBUtils;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class UsersDaoImpl implements UsersDao {

    @Override
    public boolean login(String username, String password) {
        String sql = "select * from users where username = ? and password=?";
        List argList = new ArrayList();
        ResultSet rs = null;
        try {
            argList.add(username);
            argList.add(password);
            rs = DBUtils.executeQuery(sql, argList);
            //如果rs.next==true,说明找到了登录用户，则登录成功！
            if (rs.next()) {
                return true;
            }
            return false;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        } finally {
            DBUtils.closeAll();
        }
    }
}
